<?php

class Jd_day_count_model extends MY_Model
{

    public function __construct()
    {
        $this->modelename = 'Jd_day_count_model';
        $this->tablename = 'day_count';
        parent::__construct();
    }


    public function addlog($array = array(), $web_id)
    {
        if (!$web_id) {
            $web_id = $this->web_id;
        }
        $DATE = $array['date'];
        $sql = "select id from  jd_day_count where webid=$web_id AND `date`='$DATE'";
        $r = $this->GetBySql($sql, 0);
        if ($r) {
            $array['update'] = time();
            return $r = $this->update($this->tablename, 'id', $r['id'], $array);
        }
        return $r = $this->add($this->tablename, $array);
    }

    public function getrowbydate($firstday, $lastday='', $row = array())
    {

        if ($lastday != "") {
            $firstday = strtotime($firstday) + 24 * 3600;
            $lastday = strtotime($lastday) + 36 * 3600;
            $sql = "select sum(`pay`) as 'pay',sum(`regnum`) as 'regnum' from  jd_day_count where addtime>=$firstday AND addtime<$lastday  ";
        }else{
            $sql = "select sum(`pay`) as 'pay',sum(`regnum`) as 'regnum' from  jd_day_count where `date`='$firstday' ";
        }

        if (isset($row['webid'])) {
            $webid = $row['webid'];
            $webid = intval($webid);
            if ($webid != 0) {
                $sql .= " AND webid= $webid";
            }
        } else {
            $this->web_id = intval($this->web_id);
            $sql .= " AND webid= $this->web_id";
        }


        return $this->GetBySql($sql, 0);
    }


}
